<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 * 
 * 创建时间：2021-11-06 09:22
 *
 * 项目：rm  -  $  - ViewController.php
 *
 * 作者：liwei 
 */

namespace modules\levfm\controllers;

use Lev;
use lev\base\Assetsv;
use lev\base\Controllerv;
use lev\base\Viewv;
use modules\levfm\table\form\FormData\viewValidations;
use modules\levfm\table\LevfmDatas;
use modules\levfm\table\LevfmFields;
use modules\levfm\table\LevfmForms;

!defined('INLEV') && exit('Access Denied LEV');


class ViewController extends Controllerv
{

    public static function actionIndex() {
        $viewid = Lev::GETv('opid');

        if ($viewid === null) {
            ListController::actionIndex();
            return;
        }

        $viewid = floatval($viewid);

        $info = LevfmDatas::findOne(['id'=>$viewid]);
        if (empty($info)) {
            Lev::showMessages(Lev::responseMsg(-404444, '抱歉，您查看的数据不存在'));
        }elseif ($info['status']) {
            if (Lev::$app['isAdmin']) {
                Lev::setNotices('数据未通过审核，仅管理员可看');
            }else {
                Lev::showMessages(Lev::responseMsg(-404445, '抱歉，您查看的数据已关闭显示'));
            }
        }

        $datas = LevfmDatas::getDatas($info['datas']);
        unset($info['datas']);

        $formInfo = LevfmForms::findOne(['id'=>$info['formid']]);
        $inputs = LevfmFields::getFormFields($info['formid']);

        if ($errorMsg = viewValidations::errorMessage($info, $formInfo)) {
            Lev::showMessages($errorMsg);
        }

        Lev::$app['title'] = $info['srhkey'].' - 表单数据查看';

        Assetsv::animateCss();
        Viewv::render('views/view/index', [
            'info'      => $info,
            'formInfo'  => $formInfo,
            'inputs'    => $inputs,
            'datas'     => $datas,
        ]);
    }

}